/*
 * variable_recv_server.c
 *
 *  Created on: Jun 1, 2014
 *      Author: Lhmily
 */

#include "../include/base.h"
int main(int argc, char **argv) {
	struct sockaddr_in peer;
	SOCKET s, s1;
	int n, peerlen = sizeof(peer);
	char buf[10];

	INIT();
	s = (2 == argc) ? tcp_server(NULL, argv[1]) : tcp_server(argv[1], argv[2]);
	s1 = accept(s, (struct sockaddr*) &peer, &peerlen);
	if (!isvalidsock(s1))
		error(1, errno, "accept failed");
	while (1) {
		n = readvrec(s1, buf, sizeof(buf));
		if (n < 0)
			error(1, errno, "fucntion readvrec returned error");
		else if (0 == n)
			error(1, 0, "client disconnected\n");
		else {

			write(1, buf, n);
		}
	}
	EXIT(0);
}

